﻿using Photon.Pun;
using UnityEngine;
using UnityEngine.UI;

public class RoomUI : MonoBehaviour 
{
    public InputField roomName;
    public InputField playerName;
    
    public void Join()
    {
        if (string.IsNullOrEmpty(roomName.text))
        {
            return;
        }
        Debug.LogError("JoinRoom");
        PhotonNetwork.JoinRoom(roomName.text);
        PhotonNetwork.LocalPlayer.NickName = playerName.text;
    }
    public void CreateRoom()
    {
        if (string.IsNullOrEmpty(roomName.text))
        {
            return;
        }
        PhotonNetwork.JoinOrCreateRoom(roomName.text,new Photon.Realtime.RoomOptions() { MaxPlayers=2},Photon.Realtime.TypedLobby.Default);
        //PhotonNetwork.LocalPlayer;
        PhotonNetwork.LocalPlayer.NickName = playerName.text;
    }

    public void SingleMode()
    {
        ChessController controller = GameObject.FindObjectOfType<ChessController>();
        controller.SetGameState(GameState.Ready);
        controller.gameMode = GameMode.StandAlone;
        gameObject.SetActive(true);
        GameObject obj= Resources.Load("Player")as GameObject;
        obj.GetComponent<PlayerInput>().chessType = ChessType.Black;
        Instantiate(obj);
    }
}